<?php
namespace app\appclass\controller;
use app\AdminRest;

use app\ApiRest;
use app\appclass\model\CardList;
use app\appclass\model\CardLog;
use app\appclass\model\CardUser;
use app\appclass\model\CardWater;
use app\appclass\model\ClassCard;
use app\appclass\model\ClassCate;
use app\appclass\model\ClassDate;
use app\appclass\model\ClassLable;
use app\appclass\model\ClassList;
use app\appclass\model\ClassRecord;
use app\appclass\model\ClassRoom;
use app\appclass\model\Lable;
use app\card\model\Company;
use app\payclass\model\Record;
use think\App;
use think\facade\Db;


class IndexCard extends ApiRest
{

    protected $model;

    protected $cate_model;

    protected $lable_model;

    protected $room_model;

    protected $date_model;

    public function __construct(App $app) {

        parent::__construct($app);

        $this->model       = new CardUser();

        $this->cate_model  = new ClassCate();

        $this->lable_model = new ClassLable();

        $this->room_model  = new ClassRoom();

        $this->date_model  = new ClassDate();

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-18 10:17
     * @功能说明:个人会员卡列表
     */
    public function userCardList(){

        $input = $this->_param;

        $user_id = !empty($input['user_id'])?$input['user_id']:$this->getUserId();
        //认证会员卡
        $this->model->initCardUser($user_id);
        //初始化会员卡
        $this->model->initCard($this->_uniacid);

        $input = $this->_param;

        $dis[] = ['a.uniacid','=',$this->_uniacid];

        $dis[] = ['a.user_id', '=',$user_id];


        if(!empty($input['status'])){

            $dis[] = ['a.status', '=',$input['status']];

        }else{

            $dis[] = ['a.status', '>',-1];
        }

        $data = $this->model->dataList($dis);

        if(!empty($data['data'])){

            foreach ($data['data'] as &$v){

                $v['end_time'] = date('Y-m-d',$v['end_time']);

            }
        }

        return $this->success($data);

    }

    /**
     * @author chenniang
     * @DataTime: 2021-05-20 10:14
     * @功能说明:会员预约列表
     */
    public function cardAppRecord(){

        $input = $this->_param;

        $dis = [

            'user_id' => $this->getUserId(),

            'card_id' => $input['card_id']
        ];

        $record_model = new ClassRecord();

        $data = $record_model->dataList($dis);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-20 11:17
     * @功能说明:会员卡详情
     */
    public function cardUserInfo(){

        $input = $this->_param;

        $dis = [

            'id' => $input['id']
        ];

        $data = $this->model->dataInfo($dis);

        $data['adviser_name'] = lbUserName($data['adviser']);

        $data['end_time']     = date('Y-m-d H:i:s',$data['end_time']);

        $data['create_time']  = date('Y-m-d H:i:s',$data['create_time']);

        $data['open_time']    = date('Y-m-d H:i:s',$data['open_time']);

        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-09 14:28
     * @功能说明:会员卡变更记录
     */
    public function cardLogList(){

        $input = $this->_param;

        $dis = [

            'card_user_id' => $input['card_id']
        ];

        $log_model = new CardLog();

        $data = $log_model->dataList($dis);

        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-09 14:30
     * @功能说明:会员卡记录
     */
    public function waterList(){

        $input = $this->_param;

        $water_model = new CardWater();

        $dis = [

            'card_id' => $input['card_id']

        ];

        $data = $water_model->waterList($dis);

        return $this->success($data);

    }



    




}
